package addEdges;

import java.io.IOException;

import org.apache.hadoop.io.BytesWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapred.OutputCollector;
import org.apache.hadoop.mapred.Reporter;

import removeDanglingPage.ReadBytes;

import mapred.AbstractMapper;

public class AddEdges_Mapper extends AbstractMapper<BytesWritable, BytesWritable, BytesWritable, BytesWritable>{

	@Override
	public void map(BytesWritable key, BytesWritable value,
			OutputCollector<BytesWritable, BytesWritable> output,
			Reporter reporter) throws IOException {
		// TODO Auto-generated method stub
		ReadBytes k = new ReadBytes(key);
		byte [] p = k.nextUrl();
		if(k.hasNextInt()) {
			if(k.nextInt() == 0) {
				output.collect(value, new BytesWritable(p));
			}
		} else {
			output.collect(key, value);
		}
	}

	

//	@Override
//	public void map(Text key, Text value, OutputCollector<Text, Text> output,
//			Reporter reporter) throws IOException {
		// TODO Auto-generated method stub
//		try {
//			String k = key.toString().trim();
//			String[] ks = k.split(" ");
//			if(Integer.parseInt(ks[1]) == 0) {
//				output.collect(value, new Text(ks[0]));
//			}
//		} 
//		catch (Exception e) {
//			output.collect(key, value);
//		}
//	}

}
